package com.shop2cn.iapi.member.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.member.parameter.CreateMemberBean;
import com.shop2cn.iapi.member.parameter.QueryMemberInfoBean;
import com.shop2cn.iapi.member.service.QueryMemberInfoCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.GodMemberService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.TestDataManager;
/**
*根据手机号查询电铺会员
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QueryMemberInfo{
	private static QueryMemberInfoBean QueryMemberInfoBean;
	private static QueryMemberInfoCall QueryMemberInfoCall;
	private static Integer shopid ;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据userId查手机号，然后根据手机号找到会员信息在帅选来源");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		QueryMemberInfoBean=new QueryMemberInfoBean();
		QueryMemberInfoCall=new QueryMemberInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(QueryMemberInfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryMemberInfo_001() {
		Logger.start(true,"根据userId查手机号，然后根据手机号找到最老的会员信息-查询appsource0");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setAccessSource(0);
			String memid = GodMemberService.creatememberCall(createMem);
			String mobile=TestDataManager.getPhoneNum();
			GodMemberService.bindMobile(shopid, userId, mobile);
			QueryMemberInfoBean.setUserId(userId);
			QueryMemberInfoBean.setShopId(shopid);
			QueryMemberInfoCall.setData(QueryMemberInfoBean);
			QueryMemberInfoCall.callService();			
			Logger.verifyEquals("200", QueryMemberInfoCall.getString("code"), "验证code");
			Logger.verifyEquals(mobile, QueryMemberInfoCall.getQueryMemberInfo().getMobile(), "验证openid");
			Logger.verifyEquals(userId, QueryMemberInfoCall.getQueryMemberInfo().getUserId(), "验证userid");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryMemberInfo_002() {
		Logger.start(true,"不输入shopid失败");
		try {
			QueryMemberInfoBean.setUserId(1);
//			QueryMemberInfoBean.setShopId(shopid);
			QueryMemberInfoCall.setData(QueryMemberInfoBean);
			QueryMemberInfoCall.callService();			
			Logger.verifyEquals("400", QueryMemberInfoCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryMemberInfo_003() {
		Logger.start(true,"不输入userid失败");
		try {
//			QueryMemberInfoBean.setMobile("13712163581");
			QueryMemberInfoBean.setShopId(shopid);
			QueryMemberInfoCall.setData(QueryMemberInfoBean);
			QueryMemberInfoCall.callService();			
			Logger.verifyEquals("400", QueryMemberInfoCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryMemberInfo_005() {
		Logger.start(true,"根据userId查手机号，然后根据手机号找到最老的会员信息");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setAccessSource(1);
			String memid = GodMemberService.creatememberCall(createMem);
			String mobile=TestDataManager.getPhoneNum();
			GodMemberService.bindMobile(shopid, userId, mobile);
			QueryMemberInfoBean.setUserId(userId);
			QueryMemberInfoBean.setShopId(shopid);
			QueryMemberInfoCall.setData(QueryMemberInfoBean);
			QueryMemberInfoCall.callService();			
			Logger.verifyEquals("200", QueryMemberInfoCall.getString("code"), "验证code");
			Logger.verifyEquals(mobile, QueryMemberInfoCall.getQueryMemberInfo().getMobile(), "验证openid");
			Logger.verifyEquals(userId, QueryMemberInfoCall.getQueryMemberInfo().getUserId(), "验证userid");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}